package com.lee.template.controller;

import com.lee.template.factory.TemplateFactory;
import com.lee.template.service.AbstractPayCallbackTemplate;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zfl_a
 * @date 2020/8/12
 * @project springboot_design_pattern
 */
@RestController
@RequestMapping("/template")
public class TemplateController {

    /**
     * 回调
     * @param templateId
     * @return
     */
    @GetMapping("/aysnCallBack")
    public String aysnCallBack(String templateId){

        if(StringUtils.isBlank(templateId)) {
            return "请传递支付模板id";
        }
        //从工厂中根据模板ID取出对应的模板
        AbstractPayCallbackTemplate callBackTemplate = TemplateFactory.findCallBackTemplate(templateId);
        return callBackTemplate.asynCallBack();
    }
}
